/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.yug.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.yug.entity.YugCategoryVedioRef;
import com.thinkgem.jeesite.modules.yug.service.YugCategoryVedioRefService;

/**
 * 视频种类映射Controller
 * @author Jeff
 * @version 2016-12-04
 */
@Controller
@RequestMapping(value = "${adminPath}/yug/yugCategoryVedioRef")
public class YugCategoryVedioRefController extends BaseController {

	@Autowired
	private YugCategoryVedioRefService yugCategoryVedioRefService;
	
	@ModelAttribute
	public YugCategoryVedioRef get(@RequestParam(required=false) String id) {
		YugCategoryVedioRef entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = yugCategoryVedioRefService.get(id);
		}
		if (entity == null){
			entity = new YugCategoryVedioRef();
		}
		return entity;
	}
	
	@RequiresPermissions("yug:yugCategoryVedioRef:view")
	@RequestMapping(value = {"list", ""})
	public String list(YugCategoryVedioRef yugCategoryVedioRef, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<YugCategoryVedioRef> page = yugCategoryVedioRefService.findPage(new Page<YugCategoryVedioRef>(request, response), yugCategoryVedioRef); 
		model.addAttribute("page", page);
		return "modules/yug/yugCategoryVedioRefList";
	}

	@RequiresPermissions("yug:yugCategoryVedioRef:view")
	@RequestMapping(value = "form")
	public String form(YugCategoryVedioRef yugCategoryVedioRef, Model model) {
		model.addAttribute("yugCategoryVedioRef", yugCategoryVedioRef);
		return "modules/yug/yugCategoryVedioRefForm";
	}

	@RequiresPermissions("yug:yugCategoryVedioRef:edit")
	@RequestMapping(value = "save")
	public String save(YugCategoryVedioRef yugCategoryVedioRef, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, yugCategoryVedioRef)){
			return form(yugCategoryVedioRef, model);
		}
		yugCategoryVedioRefService.save(yugCategoryVedioRef);
		addMessage(redirectAttributes, "保存视频种类映射成功");
		return "redirect:"+Global.getAdminPath()+"/yug/yugCategoryVedioRef/?repage";
	}
	
	@RequiresPermissions("yug:yugCategoryVedioRef:edit")
	@RequestMapping(value = "delete")
	public String delete(YugCategoryVedioRef yugCategoryVedioRef, RedirectAttributes redirectAttributes) {
		yugCategoryVedioRefService.delete(yugCategoryVedioRef);
		addMessage(redirectAttributes, "删除视频种类映射成功");
		return "redirect:"+Global.getAdminPath()+"/yug/yugCategoryVedioRef/?repage";
	}

}